#pragma once

#include "pch.h"

struct UdpSocket
{
    uint64_t sock;

    struct Desc
    {
        unsigned int af = AF_INET;

        unsigned int type = SOCK_DGRAM;
        unsigned int protocol = IPPROTO_UDP;

    };

    bool Create(const Desc& desc);

    void Close();

    template <typename T>
    int RecvFrom(T &revbuf, sockaddr_in &soserver)
    {
        static socklen_t addrlen = sizeof(struct sockaddr_in);
        return recvfrom(sock, (char *)&revbuf, sizeof(revbuf), 0, (sockaddr *)&soserver, &addrlen);
    }

    template <typename T>
    int SendTo(const T &senbuf, sockaddr_in &soserver)
    {
        static socklen_t addrlen = sizeof(struct sockaddr_in);
        return sendto(sock, (const char *)&senbuf, sizeof(senbuf), 0, (sockaddr *)&soserver, addrlen);
    }


};